﻿using System;
using System.Collections.Generic;
using System.Text;

public class PlayersService
{
    private const int k_PlayerVsPlayerMode = 1;
    private const char k_X = 'X';
    private const char k_O = 'O';
    private int m_GameMode = 0;
    private List<Player> m_ListOfPlayers = null;

    public int FirstPlayerScore
    {
        get { return m_ListOfPlayers[0].Score; }
    }

    public int SecondPlayerScore
    {
        get { return m_ListOfPlayers[1].Score; }
    }

    public int NumOfPlayers
    {
        get { return m_ListOfPlayers.Count; }
    }

    public PlayersService(int i_GameMode)
    {
        m_GameMode = i_GameMode;
        m_ListOfPlayers = new List<Player>();

        Player FirstPlayer = new Player(Player.ePlayerType.User, k_X);
        m_ListOfPlayers.Add(FirstPlayer);

        Player SecondPlayer = null;

        if (i_GameMode == k_PlayerVsPlayerMode)
        {
            SecondPlayer = new Player(Player.ePlayerType.User, k_O);
        }
        else
        {
            SecondPlayer = new Player(Player.ePlayerType.Pc, k_O);
        }

        m_ListOfPlayers.Add(SecondPlayer);
    }

    public Player GetPlayerByIndex(int i_Index)
    {
        return m_ListOfPlayers[i_Index];
    }

    public void UpdateWinnerScore(int i_CurrentPlayerIndex)
    {
        Player WinnerPlayer = GetPlayerByIndex(i_CurrentPlayerIndex);
        WinnerPlayer.Score += 1;
    }
}
